/**
 * @FileDescription 删除地图要素
 * @Author 祝小文
 * @Date 2022-10-10 17:14
 */
import { useChemicalStore } from '@/store'
import { insertOrUpdate } from '@/service/api'
import { ElMessage } from 'element-plus'
const chemicalStore = useChemicalStore()

/** 删除指定类型的要素 */
export const delMapFactorInfo = (item: any, type: any) => {
  if (item.sfbh === 1) {
    const params = {
      qyid: item.qyid,
      cjid: item.id,
      sfyx: 0,
    }
    insertOrUpdate(params)
      .then((res: any) => {
        item.sfbh = 0 //修改标绘状态为未标注

        removeMapFactor(item.id, type) //删除地图要素

        ElMessage.success('地图要素删除成功')
      })
      .catch(() => {
        ElMessage.error('地图要素删除失败')
      })
  }
}

/** 删除地图要素 */
export const removeMapFactor = (id: any, type: any) => {
  switch (type) {
    case 'overlay':
      window.GOverlay.removeByName(id)
      break
    case 'scrollWall':
      window.GScrollWall.removeByName(id)
      break
    case 'point':
      window.GPoint.removeByName(id)
      break
    case 'rect':
      window.GCgsRect.removeByName(id)
      break
  }
}
